﻿//======================================================================
//
//        Copyright (C) 苏州逸仙软件    
//        All rights reserved
//
//        filename :securities.aspx
//        description :证券公司列表
//
//        created by Jason at  2010-12-31 10：23
//
//======================================================================
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

namespace huaguwang.hgmanage.Securities
{
    public partial class securities : System.Web.UI.Page
    {
        D_T_SecurCompany_Exp _DAL = new D_T_SecurCompany_Exp();
        private void SetButton(int i, Button but)
        {
            switch (i)
            {
                case 1:
                    but.Attributes.Add("onclick", "return GetUpdateCheckDefault();");
                    break;
                case 2:
                    but.Attributes.Add("onclick", "return GetDelCheckDefault();");
                    break;
                default:
                    break;
            }
        }

        private huaguwang.WebControls.WebUserToolBar.SelectItem[] SetText()
        {
            huaguwang.WebControls.WebUserToolBar.SelectItem[] list = { 
                new huaguwang.WebControls.WebUserToolBar.SelectItem(){
                FuncGetText = () => this.txtTitle.Text.Trim(),
                FuncSetText = v => { this.txtTitle.Text = v; },
                Name = this.txtTitle.ID
                }, 
            };
            return list;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            AdminPublic.Try(() =>
            {
                WebUserToolBar1.MainInit(
                    UserConst.Exp_GetUser,
                    UserConst.Exp_GetButtonList,
                    SetButton,
                    UserConst.Exp_ToolBarErr,
                    SetText()
                 );
                if (!IsPostBack)
                {
                    //绑定数据
                    BindList(0);
                }
            });
        }

        //绑定数据
        private void BindList(int startindex)
        {
            AdminPublic.Try(() =>
            {
                var s1 = WebUserToolBar1.MainGetQuery(this.txtTitle.ID);
                this.Pager.RecordCount = _DAL.GetPageCount(s1);
                this.rptSecurities.DataSource = _DAL.GetPageList(startindex, Pager.PageSize, s1);
                this.rptSecurities.DataBind();
            });
        }

        /// <summary>
        /// 分页控件事件
        /// </summary>
        protected void Pager_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            AdminPublic.Try(() =>
            {
                BindList((e.NewPageIndex - 1) * Pager.PageSize);
            });
        }

        /// <summary>
        /// 增加按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void WebUserToolBar1_Button0(object sender, EventArgs e)
        {
            AdminPublic.Try(() =>
            {
                var sKey = this.WebUserToolBar1.EditSKey;
                Response.Redirect("securities_E.aspx?" + sKey, false);
            });
        }

        /// <summary>
        /// 修改按钮的事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void WebUserToolBar1_Button1(object sender, EventArgs e)
        {
            AdminPublic.Try(() =>
            {
                var strID = Request.Params["HiddenID"].Exp_Trim();
                var sKey = this.WebUserToolBar1.EditSKey;
                Response.Redirect("securities_E.aspx?ID=" + strID + "&" + sKey, false);
            });
        }

        /// <summary>
        /// 查询按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void WebUserToolBar1_Button3(object sender, EventArgs e)
        {
            AdminPublic.Try(() =>
            {
                WebUserToolBar1.MainSetQuery();
                BindList(0);
            });
        }

        /// <summary>
        /// 删除按钮的事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void WebUserToolBar1_Button2(object sender, EventArgs e)
        {
            AdminPublic.Try(() =>
            {
                var strID = Request.Params["HiddenID"].Exp_Trim();
                var delID = strID.Exp_SplitToList(',', Sel => Sel.Exp_IntTryParse()).Where(Sel => Sel > 0).ToList();
                if (delID == null || delID.Count <= 0)
                {
                    this.Exp_PageAlter("没有找到可以删除的信息");
                    return;
                }
                var iRet = _DAL.UpdateFlag(delID);
                if (iRet > 0)
                {
                    this.Exp_PageWriteLog(Log_Type.delete, "证券公司信息", delID);
                    this.Exp_PageAlter("删除操作成功");
                    BindList((Pager.CurrentPageIndex - 1) * Pager.PageSize);
                    return;
                }
                else
                {
                    this.Exp_PageAlter("删除类别信息失败");
                    return;
                }
            });
        }
    }
}
